package tengxun.com.sunny.t2;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
import java.util.concurrent.LinkedBlockingQueue;

public class Main {

    static final int MAXN = 1005;
    static int[] rudu = new int[MAXN];
    static int[] chudu = new int[MAXN];
    static boolean[] used = new boolean[MAXN];
    static HashMap<Integer, ArrayList<Integer>> map = new HashMap<>();

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        while (m-->0){
            int u = scanner.nextInt();
            int v = scanner.nextInt();
            if(map.containsKey(u)){
                map.get(u).add(v);
            }else{
                ArrayList<Integer> list = new ArrayList<>();
                list.add(v);
                map.put(u,list);
            }
        }
        for(int i=1;i<=n;i++){
            if(map.containsKey(i)){
                bfs(i);
            }
        }
        int res = 0;
        for(int i=1;i<=n;i++){
            if(rudu[i] > chudu[i]){
                res++;
            }
        }
        System.out.println(res);
    }

    public static void bfs(int s){
        Arrays.fill(used, false);
        LinkedBlockingQueue<Integer> queue = new LinkedBlockingQueue<>();
        queue.offer(s);
        used[s] = true;
        while (!queue.isEmpty()){
            int cur = queue.poll();
            if(map.containsKey(cur)) {
                for (int next : map.get(cur)) {
                    if (!used[next]) {
                        used[next] = true;
                        queue.offer(next);
                        chudu[s]++;
                        rudu[next]++;
                    }
                }
            }
        }
    }

}
